﻿function GetPosition(element) {
    var result = new Object();
    result.x = 0;
    result.y = 0;
    result.width = 0;
    result.height = 0;
    if (element.offsetParent) {
        result.x = element.offsetLeft;
        result.y = element.offsetTop;
        var parent = element.offsetParent;
        while (parent) {
            result.x += parent.offsetLeft;
            result.y += parent.offsetTop;
            var parentTagName = parent.tagName.toLowerCase();
            if (parentTagName != "table" &&
                parentTagName != "body" && 
                parentTagName != "html" && 
                parentTagName != "div" && 
                parent.clientTop && 
                parent.clientLeft) {
                result.x += parent.clientLeft;
                result.y += parent.clientTop;
            }
            parent = parent.offsetParent;
        }
    }
    else if (element.left && element.top) {
        result.x = element.left;
        result.y = element.top;
    }
    else {
        if (element.x) {
            result.x = element.x;
        }
        if (element.y) {
            result.y = element.y;
        }
    }
    if (element.offsetWidth && element.offsetHeight) {
        result.width = element.offsetWidth;
        result.height = element.offsetHeight;
    }
    else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
        result.width = element.style.pixelWidth;
        result.height = element.style.pixelHeight;
    }
    return result;
}

function GetElementById(elementId) {
    if (document.getElementById) {
        return document.getElementById(elementId);
    }
    else if (document.all) {
        return document.all[elementId];
    }
    else return null;
}

function $(elementId) {
    if (document.getElementById) {
        return document.getElementById(elementId);
    }
    else if (document.all) {
        return document.all[elementId];
    }
    else return null;
}

function GetParentByTagName(element, tagName) {
    var parent = element.parentNode;
    var upperTagName = tagName.toUpperCase();
    while (parent && (parent.tagName.toUpperCase() != upperTagName)) {
        parent = parent.parentNode ? parent.parentNode : parent.parentElement;
    }
    return parent;
}

function GetElementsByTagName(element, tagName) {
    if (element && tagName) {
        if (element.getElementsByTagName) {
            return element.getElementsByTagName(tagName);
        }
        if (element.all && element.all.tags) {
            return element.all.tags(tagName);
        }
    }
    return null;
}

function createXMLHttpRequest( ) {
    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
    try { return new XMLHttpRequest( ); } catch(e) {}
    alert("XMLHttpRequest not supported");
    return null;
}
function splitphone(inp,control)
{
//    if(((window.event.keyCode==48)||(window.event.keyCode==96))&&(inp.toString().length==1))
//    {
//        control.value='';
//        return;
//    }
    if(((window.event.keyCode<48)||(window.event.keyCode>57))&&(window.event.keyCode!=8)&&((window.event.keyCode<96)||(window.event.keyCode>105)))
    {
        control.value=inp.toString().substring(0, inp.toString().length-1);
        return;
    }
    var tmp=inp.toString();
    var p="";
    var i=0;
    var u;
    while(i<tmp.length)
    {
        u=tmp.substring(i, i+1);
        if(u!=",")
            p=p+u;
        i=i+1;
    }
    if(p.length>3)
    {
        var s=p.substring(p.length-3, p.length);
        var result="," + s;
        var t=p.substring(0,p.length-3);
        while(t.length>3)
        {
            s=t.substring(t.length-3,t.length);
            result= "," + s + result;
            t=t.substring(0, t.length-3);
        }
        result=t + result;
        control.value=result;
    }
    else control.value=p;
}
function GetUrlQueryString(qname)
{        
    var QueryString= window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');        
    for (var i = 0; i < QueryString.length; i++) 
    { 
        var name = QueryString[i].split('=')[0]; 
        var value = QueryString[i].split('=')[1];
        if(name==qname)
            return value;
    }
}
function ChangeMenuitem(inp)
{
    $('#leftmenu td').attr('class', "menuitem");
    inp.className="menuitemselected";
}
function resize(controls) {
    var myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
        myHeight = document.body.clientHeight;
    }  
    controls.style.height=myHeight - 100 + "px";
}
function resizeemp(controls) {
    var myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
    }  
    controls.style.height=myHeight - 200 + "px";
}
function resizeheight() {
    var myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
    }  
    $('container').style.height=myHeight - 100 + "px";
}
